/*
 * Funny Language - a free style programming language.
 * Copyright (C) 2015 by fanguangping (fanguangping@163.com)
 * queue.h
 */

#ifndef FUNNY_QUEUE_H
#define FUNNY_QUEUE_H

#include "string.h"

typedef struct _QueueNode {
	void *element;
	struct _QueueNode *next;
} QueueNode;

typedef struct _Queue {
	struct _QueueNode *head;
	struct _QueueNode *tail;
} Queue;

Queue *alloc_queue();
QueueNode *alloc_queue_node();

Queue *init_queue();
void enqueue(Queue *queue, void *element);
void *dequeue(Queue *queue);
void *get_queue_element(Queue *queue, int index);
int is_queue_empty(Queue *queue);
void clear_queue(Queue *queue);
void append_queue(Queue *q1, Queue *q2);
int contains_queue_element(Queue *queue, void *element, int (*equals)(void *e1, void *e2));
int get_queue_element_index(Queue *queue, void *element, int (*equals)(void *e1, void *e2));
int count_queue_element(Queue *queue);

void iterate_queue(Queue *queue, void* (*process)(void* element));
Queue* filter_queue(Queue *queue, int (*predicate)(void* element));
Queue* transform_queue(Queue *queue, void* (*process)(void* element));
Queue* transform_queue_with_data(Queue *queue, void* data, void* (*process)(void* element, void* data));
String join_from_queue(Queue *queue, String delim);
Queue* split_to_queue(String string, String delim);

#endif //FUNNY_QUEUE_H
